<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">财务管理</a>
        <a href="#">收支管理</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="layui-row">
    <form class="layui-form layui-col-md12 x-so" onsubmit="return false">
        <input type="text" style="width: 150px" name="username"  placeholder="操作人或审核人" autocomplete="off" class="layui-input">
        <div class="layui-input-inline">
            <select name="type" id="type">
                <option value="">请选择收支类型</option>
                <option value="1">收入</option>
                <option value="2">支出</option>
            </select>
        </div>
        <div class="layui-input-inline">
            <select name="status" id="status">
                <option value="">请选择收支状态</option>
                <option value="1">未审核</option>
                <option value="2">以审核</option>
            </select>
        </div>
        <input class="layui-input" placeholder="开始日" name="start" id="start" autocomplete="off">
        <input class="layui-input" placeholder="截止日" name="end" id="end" autocomplete="off">
        <button class="layui-btn"  id="search"><i class="layui-icon">&#xe615;</i></button>
    </form>
</div>
<xblock>
    <button class="layui-btn" id="add"><i class="layui-icon"></i>添加收支单</button>
</xblock>
<table id="expenses_receipts">

</table>
<script>
    layui.use(['laydate','layer'], function(){
        var laydate = layui.laydate;
        layer = layui.layer;
        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });
</script>
<script>
    $('#expenses_receipts').bootstrapTable({
        //获取行号
        language: 'zh-CN',
        todayHighlight: true,
        striped: true,//设置为 true 会有隔行变色效果
        method: 'post',//服务器数据的请求方式 'get' or 'post'
        url: "{:url('/expenses_receipts/getExpensesReceiptsInfo')}",//服务器数据的加载地址
        toolbar:'#toolbar',//
        searchOnEnterKey:true,
        sortName:'ID',//排序字段
        sortOrder : 'desc',//降序
        sidePagination: "server",   //分页方式：client客户端分页，server服务端分页（*）
        pagination: 'false',//设置为 true 会在表格底部显示分页条
        clickToSelect:'true',//设置true 将在点击行时，自动选择rediobox 和 checkbox
        singleSelect:'true',//设置True 将禁止多选
        pageSize: '15',//如果设置了分页，页面数据条数
        pageList:[15,30,50],
        //showFooter:true,
        smartDisplay:false,
        //得到查询的参数
        queryParams : function (params) {
            //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            var temp = {
                rows: params.limit,                         //页面大小
                page: (params.offset / params.limit) + 1,   //页码
                sort: params.sort,      //排序列名
                sortOrder: params.order,//排位命令（desc，asc）
                searchName:$("input[name=username]").val(),
                start:$("input[name=start]").val(),
                end:$("input[name=end]").val(),
                type:$("#type option:selected").val(),
                status:$("#status option:selected").val()
            };
            return temp;
        },
        columns: [
            //                {title:'请选择',align:'center',checkbox : true},
            {field: 'id', title: 'ID', align:'center'},
            {field: 'applicant', title: '申请人', align:'center'},
            {field: 'operator', title: '操作人', align:'center'},
            {field: 'money', title: '金额(元)', align:'center'},
            {field: 'type', title: '类型', align:'center'},
            {field: 'remarks', title: '备注', align:'center'},
            {field: 'status', title: '状态', align:'center',formatter:status},
            {field: 'create_time', title: '创建时间', align:'center'},
            {align:'center', title:'操作', formatter:operateFormatter}
        ]}
    );
    //操作按钮
    function operateFormatter(val,rows){
        if(rows.status == '以审核'){
            return [
                "<button type='button' class='btn btn-primary btn-xs' onclick='edit("+rows.id+")'>编辑</button>&nbsp;&nbsp;",
                "<button type='button' class='btn btn-danger btn-xs' onclick='del("+rows.id+")'>删除</button>"
            ].join('');
        }else{
            return [
                "<button type='button' class='btn btn-primary btn-xs' onclick='edit("+rows.id+")'>编辑</button>&nbsp;&nbsp;",
                "<button type='button' class='btn btn-default btn-xs' onclick='adopt("+rows.id+")'>审核通过</button>&nbsp;&nbsp;",
                "<button type='button' class='btn btn-danger btn-xs' onclick='del("+rows.id+")'>删除</button>&nbsp;&nbsp;"
            ].join('');
        }
    }
    function status(val,rows){
        return rows.status = rows.status == 1 ? '<span style="color: red">未审核</span>' : '以审核';
    }
    //检索
    $("#search").click(function(){
        $("#expenses_receipts").bootstrapTable(('refresh'));
    });
    //添加收支单
    $("#add").click(function(){
        window.location.href = "{:url('/expenses_receipts/add')}"
    });
    //编辑
    function edit(id){
        window.location.href = "{:url('/expenses_receipts/edit')}?id="+id;
    }
    //通过
    function adopt(id){
        layer.confirm('你确定要通过吗',{btn:['确定','取消']},function(){
            $.ajax({
                url:"{:url('/expenses_receipts/adopt')}",
                type:"post",
                data:{id:id},
                dataType:"json",
                success:function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            $("#expenses_receipts").bootstrapTable(('refresh'));
                        })
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000})
                    }
                }
            });
        })
    }
    //删除
    function del(id){
        layer.confirm('你确定要删除吗',{btn:['确定','取消']},function(){
            $.ajax({
                url:"{:url('/expenses_receipts/delete')}",
                type:"post",
                data:{id:id},
                dataType:"json",
                success:function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            $("#expenses_receipts").bootstrapTable(('refresh'));
                        })
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000})
                    }
                }
            });
        })
    }

</script>
</body>
</html>